package cn.thoughtworks.school.repositories;

import cn.thoughtworks.school.entities.Topic;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface TopicDiffRepository extends JpaRepository<Topic, Long> {
    @Query(value = "select * from topic where id in (\n" +
        "select max(id) from topic t where\n" +
        "t.programId in ?1  group by programId,topicId order by topicId desc\n" +
        ") and operation != 2 ",nativeQuery = true)
    List<Topic> findFirst1ByIdAndProgramIdInOrderByProgramsIdDesc(List<Long> programIds);

    Topic findFirst1ByTopicIdOrderByIdDesc(Long programId);

}
